{% extends 'oratk_app/master.html' %}
{% block tag_left %}
    {% include 'oratk_app/tag_left_user.html' %}
{% endblock %}
{% block userinfo %}
    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
        <h2 class="page-header">计划任务管理</h2>
        <form class="navbar-form navbar-left" role="search">
            {#                <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"  aria-hidden="true" ></span><a href="/basic_app/user_add"> 添加用户</a></button>#}
            <div class="form-group">
                <input type="text" name="user_search" class="form-control aa_search" placeholder="Search">
            </div>
            <button type="submit" class="btn btn-default"  id="aa_search" aa_search="{{ search }}">
                <span class="glyphicon glyphicon-search" aria-hidden="true"></span> 搜索
            </button>
            <button type="button" class="btn btn-default"
                    onclick="javascrtpt:window.location.href='/oratk_app/cron_task_mgr_add'"><span
                    class="glyphicon glyphicon-plus" aria-hidden="true"></span> 添加sql类计划任务
            </button>
                        <button type="button" class="btn btn-default"
                    onclick="javascrtpt:window.location.href='/oratk_app/cron_task_mgr_add_host'"><span
                    class="glyphicon glyphicon-plus" aria-hidden="true"></span> 添加主机类计划任务
            </button>
        </form>
        <table class="table table-striped table-bordered table-hover">
            <thead>
            <tr>
                <th style="display: none">id</th>
                <th>名称</th>
                <th>描述</th>
                <th>任务类型</th>
                <th>定时时间</th>
                <th>监控项</th>
                <th>实例(个数)</th>
                <th>任务模板</th>
                <th>是否有阀值</th>
                <th>阀值</th>
                <th>是否发送短信</th>
                <th>短信联系人(个数)</th>
                <th>邮件联系人(个数)</th>
                <th>最后执行时间</th>
                <th>更改时间</th>
                <th>创建时间</th>
                <th>状态</th>
                <th>备注</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody id="tab">
            {% for i in current_page %}
                <tr>
                    <td style="display: none">{{ i.id }}</td>
                    <td>{{ i.name }}</td>
                    <td>{{ i.name__description }}</td>
                    <td>{{ i.task_type }}</td>
                    <td>{{ i.task_time }}</td>
                    <td>{{ i.task_point }}</td>
                    <td ><span id="instance" title='{{ i.instance  }}'> {{ i.instance }}</span></td>
                    <td>{{ i.task_info }}</td>
                    <td id="limit_status">{{ i.limit_status }}</td>
                    <td>{{ i.limit | default_if_none:""   }}{{ i.limit_unit | default_if_none:""   }}</td>
                    <td id="sms_status">{{ i.sms_status }}</td>
                    <td ><span id="sms_contact" title='{{ i.sms_contact  }}'> {{ i.sms_contact }}</span></td>
                    <td ><span id="email_contact" title='{{ i.email_contact  }}'> {{ i.email_contact }}</span></td>
                    <td>{{ i.name__date_changed | date:'Y-m-d H:i:s' }}</td>
                    <td>{{ i.chtime  }}</td>
                    <td>{{ i.crtime | date:'Y-m-d H:i:s' }}</td>
                    <td name="enabled"  id="enabled">{{ i.name__enabled }}</td>
                    <td>{{ i.remake }}</td>
                    <td ><a href="/oratk_app/cron_task_mgr_edit?nid={{ i.id }}">编辑</a> | <a
                            href="/oratk_app/cron_task_mgr_delete?nid={{ i.id }}">删除</a> | <a
                            href="/oratk_app/cron_task_mgr_lock?nid={{ i.id }}">停用</a> | <a
                            href="/oratk_app/cron_task_mgr_enable?nid={{ i.id }}">启用</a></td>
                </tr>
                <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">关闭</button>
                                <h4 class="modal-title" id="myModalLabel">实例详情</h4>
                            </div>
                            <div class="modal-body">{{ i.instance }}</div>
                        </div><!-- /.modal-content -->
                    </div><!-- /.modal -->
                </div>
            {% endfor %}
            </tbody>
        </table>
        {#        以上是分页#}
        {% include 'basic_app/paginator.html' %}

    </div>



{% endblock  %}
{% block script %}
    <script>
        //将计划任务的enabled状态进行转义
        $(document).ready(function(){
            $('#tab tr').each(function(){
                //var td_limit_status_val = $(this).find('td:eq(6)').text();
                //var td_limit_status_val = $(this).find('#limit_status').text()
                var td_limit_status_val = $(this).find('#limit_status').text()
                var td_sms_status_val = $(this).find('#sms_status').text();
                var td_val = $(this).find('#enabled').text();
                //将实例列表换成个数
                var ins_str = $(this).find('#instance').text()
                var ins_arr = eval('('+ins_str+')')
                $(this).find('#instance').text(ins_arr.length)
                //将短信联系人列表转换成个数
                var sms_contact_str = $(this).find('#sms_contact').text()
                var sms_contact_arr = eval('('+sms_contact_str+')')
                $(this).find('#sms_contact').text(sms_contact_arr.length)
                //将邮件联系人列表转换成个数
                var email_contact_str = $(this).find('#email_contact').text()
                var email_contact_arr = eval('('+email_contact_str+')')
                $(this).find('#email_contact').text(email_contact_arr.length)
                //转换 短信状态的值
                if( td_limit_status_val == 1 ){
                    $(this).find('#limit_status').text('是')
                }else{
                    $(this).find('#limit_status').text('否')
                }
                //转换 邮件状态的值
                if( td_sms_status_val == 1 ){
                    $(this).find('#sms_status').text('是')
                }else{
                    $(this).find('#sms_status').text('否')
                }
                //转换启用状态的值
                if( td_val == 'True' ){
                    $(this).find('#enabled').text('已启用')
                }else{
                    $(this).find('#enabled').text('已停用')
                }
            })
        })

    </script>
{% endblock %}
